<script setup lang="ts">
import {fetchFooter} from '../request/req.ts'
import {useRoute} from "vue-router";
import {computed, onMounted, ref, watch} from "vue";
import {BACKEND_URL} from "../request/Api.ts";

/**
 * 获取信息
 */
const route = useRoute()

const message = ref({
  Id: null,
  Contents: '',
  Title: ''
})
//处理图片
const descHtml = computed(() => {
  const req = message.value.Contents || ''
  return req.replace(/src=\"(?!https?:)(\/[^\"]+)\"/g, (_m, p1) => `src=\"${BACKEND_URL}${p1}\"`)
})
const getMessage = async () => {
  const res = await fetchFooter({id: route.query.id})
  message.value = res.Article
}

onMounted(() => {
  getMessage()
})

//监听路由变化
watch(() => route.query.id, () => {
  getMessage()
})
</script>

<template>
  <div class="message-page">
    <div class="message-container">
      <div class="title">
        <h2>{{ message.Title }}</h2>
      </div>
      <div class="message-content" v-html="descHtml"></div>
    </div>
  </div>
</template>

<style scoped>
.title {
  text-align: center;
  color: rgba(174, 174, 174, 0.82);
}

.message-page {
  width: 100%;
}

.message-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}

.message-content {
  color: rgba(218, 218, 218, 0.87);
  line-height: 1.8;
  font-size: 14px;
}

.message-content :deep(img) {
  max-width: 100%;
  height: auto;
  display: block;
}

.message-content :deep(table) {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.message-content :deep(pre) {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-content :deep(iframe) {
  max-width: 100%;
}

@media (max-width: 768px) {
  .message-container {
    padding: 12px;
  }
  .message-content {
    font-size: 13px;
    line-height: 1.6;
  }
}

@media (max-width: 480px) {
  .message-container {
    padding: 10px;
  }
  .title h2 {
    font-size: 18px;
  }
  .message-content {
    font-size: 12px;
  }
}
</style>
